#include "task_server_cmd.hpp"

#include <event2/event.h>
#include <event2/bufferevent.h>
#include <glog/logging.h>
task_server_cmd::task_server_cmd(/* args */)
{
}

task_server_cmd::~task_server_cmd()
{
}
void task_server_cmd::registration_command(std::string cmd,task_data* call_task)
{
    if(!call_task)
    {
        VLOG(3)<<"xftp_server_cmd reg call error";
        return;
    }
    if(cmd.empty())
    {
        VLOG(3)<<"xftp-server_cmd cmd is error";
        return;
    }
    if(m_call_task.find(cmd) != m_call_task.end())
    {
        // 已经注册的命令提示错误
        VLOG(3)<<"xftp_server cmd is register";
        return;
    }
    m_call_task[cmd] = call_task;
    VLOG(0)<<"m_call_task cmd = "<<cmd;
}
void task_server_cmd::init()
{
    VLOG(0)<<"task_server_cmd init()";
    
    bufferevent* buffer = bufferevent_socket_new(m_base,m_sockfd,BEV_OPT_CLOSE_ON_FREE);
    m_data_buffer = buffer;
    // 设置缓冲区
    set_event_callback(buffer,this);
    timeval data_time={60,0};
    bufferevent_set_timeouts(buffer,&data_time,NULL);
    std::string msg = "Welcome to the file management server RRmove\n\
    ===============================\n\
    ===============================\r\n\r\n";
    bufferevent_write(buffer,msg.c_str(),msg.size());

}